package cn.blue.org.controller;

import cn.blue.base.config.BussinessException;
import cn.blue.base.query.BaseQuery;
import cn.blue.base.util.AjaxResult;
import cn.blue.base.util.PageList;
import cn.blue.org.domain.Systemdictionarydetail;
import cn.blue.org.domain.Systemdictionarytype;
import cn.blue.org.service.SystemdictionarydetailService;
import cn.blue.org.service.SystemdictionarytypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dic")
public class SystemdictionarytypeController {
        @Autowired
        private SystemdictionarytypeService systemdictionarytypeService;
        @Autowired
        private SystemdictionarydetailService systemdictionarydetailService;
        //删除
        @DeleteMapping("/{id}")
        public AjaxResult delete(@PathVariable("id") Long id) {
            if(id==null){
                throw new BussinessException("参数不能为空");
            }
            else {
                systemdictionarytypeService.del(id);
                systemdictionarydetailService.delBytypeId(id);
                return AjaxResult.me().setSuccess(true).setMsg("请求成功");
            }
        }

        //新增或者修改
        @PutMapping
        public AjaxResult addOrUpdate(@RequestBody Systemdictionarytype systemdictionarytype) {
            System.out.println(systemdictionarytype);
            if (null == systemdictionarytype.getId()) {
                systemdictionarytypeService.add(systemdictionarytype);
            }else {
                systemdictionarytypeService.update(systemdictionarytype);
            }
            return AjaxResult.me().setSuccess(true).setMsg("请求成功");


        }
        @ResponseBody
        @RequestMapping
        public PageList<Systemdictionarytype> queryPage(@RequestBody BaseQuery query){
            PageList<Systemdictionarytype> list = systemdictionarytypeService.queryByPage(query);
            return list;


        }

        //批量删除
        @PatchMapping
        public AjaxResult batchDel(@RequestBody List<Long> ids){
            System.out.println(ids);
            systemdictionarytypeService.batchDel(ids);
            return AjaxResult.me().setSuccess(true).setMsg("删除成功");

        }

        //字典数据字典明细表下拉
        @RequestMapping("/low")
        public List<Systemdictionarytype> findAll(){
            return systemdictionarytypeService.findAll();
        }

        //获取类型下拉框



    }



